<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../js/jquery-1.8.3.min.js"></script>
    <script src="../js/common.js"></script>
</head>
<body>
    payList
    <hr>
    <input type="button" value="所有" id="all" onclick="findByState(null,1)">
    <input type="button" value="已交" id="deal" onclick="findByState(1,1)">
    <input type="button" value="未交" id="undeal" onclick="findByState(0,1)">
    <div class="payList">
    </div>
</body>
</html>
<style>
    #tab{
        /*border-collapse: collapse;*/
        width: 600px;
        font-size: 12px;
        text-align: center;
    }
</style>
<script>
    function format(millisecond){
        time = new Date(millisecond);
        var year = time.getFullYear()+'年';
        var month = time.getMonth()+1+'月';
        var date = time.getDate()+'日   ';
        var hour = time.getHours()+":";
        var minute = time.getMinutes()+":";
        var second = time.getSeconds();
        return [year,month,date].join('-')+hour+minute+second;
    }

    $(function () {
        var json = parseUrl();
        console.log(json.state);
        if(json.state == undefined || json.state == null){
            findByState(null,1);
        }
        else{
            findByState(json.state);
        }
    });

    function findByState(state,paramPage) {
        console.log("状态为"+state);
        console.log(paramPage);
        var url = "pay/findAll";
        if(state == 0 || state == 1){
            url = "pay/findByState";
        }
        var json = parseUrl();
        var page;
        if(paramPage != undefined){
            page = paramPage;
        }else{
            page = json.page;
        }

        $.ajax({
            url: url,
            type: "get",
            data:{"state":state,"page":page},
            dataType: "json",
            success: function (resp) {
                if(resp.httpCode == 200){
                    console.log("success");
                    // console.log(resp.data.length)
                    $(".payList").html("");
                    $(".payList").append(
                        "<table border='1' id='tab'>" +
                        "<tr>" +
                        "<td>缴费房号</td>"+
                        "<th>缴费原因</th>"+
                        "<th>缴费产生时间</th>"+
                        "<th>缴费状态</th>"+
                        "<th>缴费时间</th>"+
                        "</tr>"+
                        "</table>"
                    )
                    var payList = resp.data;
                    for(var i=0; i<payList.length; i++){
                        var payState = "";
                        if(payList[i].payState == 0){
                            payState = "未交";
                        }else{
                            payState = "已交";
                        }
                        // console.log(payList[i].productTime);
                        var pruductTime = format(payList[i].productTime);
                        var payTime = ""
                        // console.log(payList[i].payTime);
                        if(payList[i].payTime != undefined){
                            payTime = format(payList[i].payTime);
                        }
                        $("#tab").append(
                            "<tr>" +
                            "<td>"+payList[i].houseId+"</td>"+
                            "<td>"+payList[i].payReason+"</td>"+
                            "<td>"+pruductTime+"</td>"+
                            "<td>"+payState+"</td>"+
                            "<td>"+payTime+"</td>"+
                            "</tr>"
                        )
                    }
                    if(resp.page == 1 && resp.maxPage == 1){
                        $("#tab").append(
                            "<tr>" +
                            "<td colspan='6'> 第"+resp.page+"页  共"+resp.maxPage+"页</td>"+
                            "</tr>"
                        )
                    }else if(resp.page == 1){
                        $("#tab").append(
                            "<tr>" +
                            "<td colspan='6'>第"+resp.page+"页  共"+resp.maxPage+"页" +
                            " <a href='payList.html?state="+state+"&page="+parseInt(resp.page+1)+"'>下一页</a> </td>"+
                            "</tr>"
                        )
                    }else if(resp.page == resp.maxPage){
                        $("#tab").append(
                            "<tr>" +
                            "<td colspan='6'><a href='payList.html?state="+state+"&page="+parseInt(resp.page-1)+"'>上一页" +
                            "</a> 第"+resp.page+"页  共"+resp.maxPage+"页</td>"+
                            "</tr>"
                        )
                    }else{
                        $("#tab").append(
                            "<tr>" +
                            "<td colspan='6'><a href='payList.html?state="+state+"&page="+parseInt(resp.page-1)+"'>上一页" +
                            "</a> 第"+resp.page+"页  共"+resp.maxPage+"页 " +
                            "<a href='payList.html?state="+state+"&page="+parseInt(resp.page+1)+"'>下一页</a> </td>"+
                            "</tr>"
                        )
                    }
                }
            }
        })
    }

</script>
